#include "NtupleLoader.C"
#include <iostream>
#include <sstream>

/*
 btag = true : with btagging cut on event selection
 btag = false: without btagging cut on event selection

 tria = true : with triangle cut on event selection
 tria = false: without triangle cut on event selection

 test = true : using data10 test sample (periodG)
 test = false: using all data10 data 
*/

int run_analysis(const bool btag=false, const bool tria=false, const float d0sig_t=5.0, const bool test=false, const Int_t cache_size=10000000) {

   // TSelector object
   TSelector * s = TSelector::GetSelector("EventSelector.C");

   // making up selector options
   ostringstream stm;
   stm << "d0sig=" << d0sig_t;
   if (btag) stm << " cbtagging";
   if (tria) stm << " ctriangle";

   TString data_opts = TString( stm.str() ) + " hscale=1.0";

   TChain* myChain;

   Double_t scale = 1.0;
   if (test) {
       scale  = getIntLumi("data10_test");
       myChain = load_sample("data10_test");
   }
   else {
       scale  = getIntLumi("data10");
       myChain = load_sample("data10");
   }

   // TreeCache
   if (cache_size > 0) {
       TTreeCache::SetLearnEntries(10);  // we can take the decision after 10 entry
   }

   stm << " hscale=" << scale;
   TString mc_opts = TString( stm.str() );

   cout << data_opts << endl;
   cout << mc_opts << endl;

   // data sample
   myChain->Process(s, data_opts + " sample=data10" );

   // MC sample 
   myChain = load_sample("mc_ttbar");
   myChain->Process(s, mc_opts + " sample=mc_ttbar");

   myChain = load_sample("mc_stop");
   myChain->Process(s, mc_opts + " sample=mc_stop");

   myChain = load_sample("mc_wjets");
   myChain->Process(s, mc_opts + " sample=mc_wjets");

   myChain = load_sample("mc_zjets");
   myChain->Process(s, mc_opts + " sample=mc_zjets");

   myChain = load_sample("mc_diboson");
   myChain->Process(s, mc_opts + " sample=mc_diboson");

   myChain = load_sample("mc_qcd");
   myChain->Process(s, mc_opts + " sample=mc_qcd");

   myChain = load_sample("mc_qcdbb");
   myChain->Process(s, mc_opts + " sample=mc_qcdbb");

   myChain = load_sample("mc_mix");
   myChain->Process(s, mc_opts + " sample=mc_mix");

   return 0;
}
